//
//  XGAnswerQuestionTableViewCell.swift
//  TodayNews
//
//  Created by monkey on 2020/3/8.
//  Copyright © 2020 itcast. All rights reserved.
//

import UIKit

class XGAnswerQuestionTableViewCell: UITableViewCell, XGRegisterReusableViewProtocol
{
    var answerQuestionViewModel: XGAnswerQuestionViewModel? {
        didSet {
            titleLabel.text = answerQuestionViewModel?.question
            contentLabel.text = answerQuestionViewModel?.answer
            infoLabel.text = answerQuestionViewModel?.infoString
        }
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?)
    {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUpUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var titleLabel = UILabel(text: "测试", textColor: UIColor.black, fontSize: 17, textAlignment: .left)
    private lazy var contentLabel = UILabel(text: "测试", textColor: UIColor.lightGray, fontSize: 15, textAlignment: .left)
    private lazy var infoLabel = UILabel(text: "测试", textColor: UIColor.lightGray, fontSize: 13, textAlignment: .left)
}

private extension XGAnswerQuestionTableViewCell
{
    func setUpUI() -> Void
    {
        let lineView = UIView()
        lineView.backgroundColor = UIColor(white: 0.9, alpha: 1)
        contentView.addSubview(lineView)
        contentView.addSubview(titleLabel)
        contentView.addSubview(contentLabel)
        contentView.addSubview(infoLabel)
        lineView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(5)
        }
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(lineView.snp.bottom).offset(5)
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
        }
        contentLabel.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(5)
            make.left.right.equalTo(titleLabel)
            make.height.lessThanOrEqualTo(66)
        }
        infoLabel.snp.makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp.bottom).offset(5)
            make.left.right.equalTo(titleLabel)
        }
    }
}
